﻿CREATE procedure dbo.GetAvailableMenus
(
		@UserID int,
		@PortalID int
	)

AS

set nocount off
	

SELECT    DISTINCT dbo.TakeoutProvider.Id, dbo.TakeoutProvider.ExpirationTime, dbo.Menus.Name, dbo.TakeoutProvider.TakeoutCharge, dbo.TakeoutProvider.StartTime, 
                      dbo.TakeoutProvider.UserID AS UserID
FROM         dbo.TakeoutProvider INNER JOIN
                      dbo.TakeoutProviderAudiences ON dbo.TakeoutProvider.Id = dbo.TakeoutProviderAudiences.TakeoutProviderId INNER JOIN
                      dbo.Menus ON dbo.TakeoutProvider.MenuID = dbo.Menus.Id INNER JOIN
                      dbo.AudienceMembers ON dbo.TakeoutProviderAudiences.AudienceId = dbo.AudienceMembers.AudienceId
WHERE     (dbo.AudienceMembers.UserID = @UserID) AND (dbo.TakeoutProvider.[SiteID] = @PortalID) AND (dbo.TakeoutProvider.MaximumOrders > 0) AND 
                      (DATEDIFF(minute, GETDATE(), dbo.TakeoutProvider.ExpirationTime) > 0)


